﻿using System;
using FunctionalCLR.Core;
using Zove.Runtime;
using Zove.Shell;
using FunctionalCLR.Shell;

namespace Zove.Shell.Modelling
{
    public class AssumeNode : ContextFuncNode
    {
        public AssumeNode()
            : base() {
            base.Value = "assume";
        }

        public IZoveShellContext ZoveShellContext
        {
            get
            {
                return base.Context as IZoveShellContext;
            }
        }

        public override object Evaluate()
        {
            int length = Parameters.Count;
            if (length < 1)
            {
                throw new ArgumentException(
                    "usage: assume(factorName)");
            }

            string factorName = Convert.ToString(
                Parameters[0].Evaluate());
            RuntimeFactor factor
                = ZoveShellContext.GetFactor(
                factorName);
            if (factor == null)
            {
                throw new FactorNotDeclaredException(
                    factorName);
            }

            factor.Value = 0;
            factor.Status = RuntimeFactorStatus.Input;

            return factor;
        }
    }
}
